package xyz.zyl2020.jpa.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Repository;
import org.springframework.util.concurrent.ListenableFuture;
import xyz.zyl2020.jpa.entity.User;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author ZhuYinglong
 * @date 2020/8/25 0025
 */
@Repository
public interface UserDao extends JpaRepository<User, Long> {

    User findByAccount(String account);

    @Transactional
    void deleteByAccount(String account);

    List<User> findByAccountAndName(String account, String name);

    @Async
    ListenableFuture<List<User>> findByName(String name);

    @Query("select u from User u where u.account = ?1")
    User selectByAccount(String account);

    @Transactional
    @Modifying
    @Query("update User u set u.pwd = ?2 where u.id = ?1")
    int updatePassword(Long id, String password);
}
